
//
//  GYWelcomeViewController.swift
//  Weibo
//
//  Created by vane on 16/8/11.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class GYWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    private lazy var bgImageView:UIImageView = UIImageView(imgName: "ad_background")
    
    private lazy var userImageView:UIImageView = {
        
       let img = UIImageView(imgName: "avatar_default_big")
        
        img.gy_setImageWithString(GYUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        
        
        
        return img
    }()
    
    private var welcomeLabel:UILabel = {
        
        let lab = UILabel()
        lab.text = "欢迎回来"
        lab.textAlignment = .Center
        lab.font = UIFont.systemFontOfSize(18)
        lab.textColor = UIColor.redColor()
        lab.alpha = 0
        
        return lab
    }()
    private func setupUI(){
        
        view.addSubview(bgImageView)
        view.addSubview(userImageView)
        view.addSubview(welcomeLabel)
        
        bgImageView.snp_makeConstraints { (make) -> Void in
            
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
            
        }
        userImageView.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            
        }
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)

            make.top.equalTo(userImageView.snp_bottom).offset(16)

        }
        
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
       self.userImageView.snp_updateConstraints { (make) -> Void in
        
        make.top.equalTo(view).offset(140)

        }
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    
                    self.welcomeLabel.alpha = 1
                    
                    }, completion: { (_) -> Void in
                        
                         NSNotificationCenter.defaultCenter().postNotificationName(WBNOTIFICATIONCENTERNAME, object: nil)
                        
                })
                
        }
        
    }


}